package com.mimc.framework.events;

import com.alibaba.fastjson.JSON;
import com.jfinal.aop.Inject;
import com.mimc.common.constant.EventConstants;
import com.mimc.core.model.SysOptLog;
import com.mimc.core.service.SysOptLogService;
import com.mimc.service.ShSysMenuService;
import io.jboot.components.event.JbootEvent;
import io.jboot.components.event.JbootEventListener;
import io.jboot.components.event.annotation.EventConfig;
import lombok.extern.slf4j.Slf4j;

@EventConfig(action = {EventConstants.OPTLOGEVENT})
@Slf4j
public class OptLogEventListener implements JbootEventListener {
    @Inject
    private ShSysMenuService shSysMenuService;
    @Inject
    private SysOptLogService sysOptLogService;
    @Override
    public void onEvent(JbootEvent event) {
        log.info("操作日志：{}",event.getData().toString());
        SysOptLog sysOptLog= JSON.parseObject(event.getData().toString(),SysOptLog.class);
        sysOptLog.setTitle(shSysMenuService.getOptName(sysOptLog.getUrl()));
        sysOptLogService.save(sysOptLog);
    }
}
